﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using System.Windows.Forms;
namespace QuanLiBongDa.DataAccessLayer
{
    class CT_TranDauDAO
    {
        public static CT_TranDauDAO CreateCT_TranDauDAO()
        {
            return new CT_TranDauDAO();
        }
        public bool Insert_CTTD(CT_TranDauDTO ct)
        {
            SqlParameter[] par = new SqlParameter[4];
            par[0] = new SqlParameter("@MaTD",ct.MaTD);
            par[1] = new SqlParameter("@MaCT",ct.MaCT);
            par[2] = new SqlParameter("@MaLBT",ct.MaLBT);
            par[3] = new SqlParameter("@ThoiDiem",ct.ThoiDiem);
            return SQLService.mmExecuteNonquery("Insert_CTTD", par);
        }
        public bool Update_CTTD(CT_TranDauDTO ct)
        {
            SqlParameter[] par = new SqlParameter[4];
            par[0] = new SqlParameter("@MaTD", ct.MaTD);
            par[1] = new SqlParameter("@MaCT", ct.MaCT);
            par[2] = new SqlParameter("@MaLBT", ct.MaLBT);
            par[3] = new SqlParameter("@ThoiDiem", ct.ThoiDiem);
            return SQLService.mmExecuteNonquery("Update_PHU", par);
        }
        public bool Delete_CTTD(CT_TranDauDTO ct)
        {
            SqlParameter[] par = new SqlParameter[4];
            par[0] = new SqlParameter("@MaTD", ct.MaTD);
            par[1] = new SqlParameter("@MaCT", ct.MaCT);
            par[2] = new SqlParameter("@MaLBT", ct.MaLBT);
            par[3] = new SqlParameter("@ThoiDiem", ct.ThoiDiem);
            return SQLService.mmExecuteNonquery("Delete_CTTD", par);
        }
        public void MaTD(ComboBox matran)
        {
            SqlDataReader dr = SQLService.mExecuteReader(SQLService.ReturnAll("TRANDAU"));
            while (dr.Read())
                matran.Items.Add(dr["MaTD"]);
        }
        public void MaDB(ComboBox c,ComboBox b)
        {
            string s = "";
            if (c.SelectedItem == null)
                MessageBox.Show("Ban chua chon ma tran dau");
            else
            {
                s = c.SelectedItem.ToString();
            }
            SqlParameter [] par=new SqlParameter [1];
            par[0] = new SqlParameter("@MaTD",s);
            SqlDataReader dr = SQLService.mmExecuteReader("MaDoi_MaTD", par);
            while (dr.Read())
            {
                b.Items.Add(dr["TenDoi"]);

            }
        }
        public void MaCT(ComboBox a,ComboBox b)
        {
            string s = "";
            if (a.SelectedItem == null)
                MessageBox.Show("Bạn chưa chọn mã trận đấu");
            else
            {
                s = a.SelectedItem.ToString();
            }
            SqlParameter []par=new SqlParameter [1];
            par[0] = new SqlParameter("@MaTD", s);
            SqlDataReader dr = SQLService.mmExecuteReader("MaCT_MaTD", par);
            while(dr.Read())
            {
                b.Items.Add(dr["TenCT"]);
            }
        }
    }
}
